﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebNext.UI.Utils
{
	public class ValidationResult
	{
		private IList<string> errors;

		public bool IsValid
		{
			get { return this.errors.Count == 0; }
		}

		public ValidationResult()
		{
			this.errors = new List<string>();
		}

		public ValidationResult AddError(string error, params object[] insertionStrings)
		{
			this.errors.Add(string.Format(error, insertionStrings));
			return this;
		}

		public ValidationResult Merge(ValidationResult otherResult)
		{
			foreach (string error in otherResult.errors)
			{
				this.errors.Add(error);
			}
			return this;
		}

		public string GetErrorsMessage()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (string error in this.errors)
			{
				stringBuilder.AppendLine(error);
			}
			return stringBuilder.ToString();
		}

		public IEnumerable<string> GetErrors()
		{
			return this.errors;
		}
	}
}
